import {Component} from "react"
let scaleObj:Iscale={
    c:'摄氏度',
    f:'华氏度'
}
// 类型
type Iprops={
    scale:string;
    temperature:string;
    onTemperatureChange:(t:string)=>void
}
class TemperatureInput extends Component<Iprops,any>{
    state={
        temperature:""
    }
    handleChange=(e:any)=>{
        // console.log(e.target.value);
        // this.setState({
        //     temperature:e.target.value
        // })
        this.props.onTemperatureChange(e.target.value)
    }
    render(): React.ReactNode {
        // 解构属性
        let {scale,temperature} =this.props
        return(
            <fieldset>
                <legend>{scaleObj[scale]}</legend>
                <input type="text" value={temperature} onChange={this.handleChange}/>
            </fieldset>
        )
    }
}

export default TemperatureInput